from django.db import models


class Role(models.Model):
    role_name = models.CharField(max_length=32, unique=True)

    class Meta:
        db_table = "pp_role"


class Classroom(models.Model):
    class_name = models.CharField(max_length=32, verbose_name="班级名称", unique=True)
    address = models.CharField(max_length=32, null=True)

    class Meta:
        db_table = "pp_class"

    def __str__(self):
        return self.class_name


class User(models.Model):
    username = models.CharField(max_length=32, verbose_name="姓名")
    age = models.IntegerField(verbose_name="年龄")
    home = models.CharField(verbose_name="家乡", null=True, max_length=32)
    hight = models.IntegerField(verbose_name="身高", null=True)

    # 多对多
    roles = models.ManyToManyField(Role)

    # 一对多
    classrooms = models.ForeignKey(Classroom, on_delete=models.CASCADE, null=True)

    class Meta:
        db_table = "pp_user"
